window.onload = function(){
	a = new Application(this);
}

var cookieManager = Components.classes["@mozilla.org/cookiemanager;1"].getService(Components.interfaces.nsICookieManager);

function Application(win){
	this.win = win;
	this.win.user = false;
	
	this.win.APP = this;
	
	this.login = function(){
		inptUsername = $("#username");
		inptPassword = $("#password");
		for(var i=0; i<CREDENTIALS.length; i++){
			if(CREDENTIALS[i].username==inptUsername.val() && CREDENTIALS[i].password==inptPassword.val()){
				this.win.user = inptUsername.val();
				break;
			}
		};
		if(!this.win.user){
			$("#login-error").css("display","block");
			setTimeout(function(){
				$("#login-error").css("display","none");
			}, 3000);
		}else{
			$("#login-form").hide();
			$("#application").show();
		}
	}
	
	// Initialization
	if(this.win.user){
		$("#login-form").hide();
		$("#application").show();
	}else{
		$("#login-form").show();
		$("#application").hide();
	}
};